package com.ihr360.payroll.model.dto.salary.convertor;

import com.google.common.collect.Lists;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.payroll.config.SalaryFieldTypeEntity;
import com.ihr360.payroll.entity.staff.SalaryProfileFieldEntity;
import com.ihr360.payroll.model.dto.salary.basecode.SalaryFieldType;
import com.ihr360.payroll.model.dto.staff.SalaryProfileField;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author richey
 */
@Component
public class SalaryProfileFieldConvertor implements IConvertor<SalaryProfileFieldEntity, SalaryProfileField> {

    @Override
    public SalaryProfileField convertEntityToDto(SalaryProfileFieldEntity entity) {
        return null;
    }

    @Override
    public SalaryProfileFieldEntity convertDtoToEntity(SalaryProfileField dto) {

        if (dto == null) {
            return null;
        }

        SalaryProfileFieldEntity entity = new SalaryProfileFieldEntity();
        BeanUtils.copyProperties(dto,entity);

        SalaryFieldType type = dto.getType();
        if (type != null) {
            SalaryFieldTypeEntity typeEntity = new SalaryFieldTypeEntity();
            BeanUtils.copyProperties(type,typeEntity);
            entity.setType(typeEntity);
        }
        return entity;
    }


    public List<SalaryProfileFieldEntity> converDtosToEntities(List<SalaryProfileField> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Lists.newArrayList();
        }
        List<SalaryProfileFieldEntity> entities = Lists.newArrayListWithCapacity(dtos.size());
        dtos.forEach(dto ->{
            entities.add(convertDtoToEntity(dto));
        });
        return entities;
    }

}
